$(function () {
	vm.getMentor();
	$('#firstTab a').click(function(e) {
		e.preventDefault(); //阻止a链接的跳转行为
		$(this).tab('show'); //显示当前选中的链接及关联的content
		vm.refreshData($(this).attr('id'));
	});
	$('#yiyuyue').click();
});

var vm = new Vue({
    el: '#mapp',
    data: {
        announcement: '欢迎来自安徽的周童小朋友,大家热烈欢迎~',
        bsnMentor:{},
        bsnFinished:{},
        bsnNotFinished: {},
        pageParams:{
			limit: "200",
			page: "1"
		},
        teacherNotice: '导师须知：导师应遵守平台的各项管理规定，不可随意取消预约等'
    },
    methods: {
		//获取导师信息
		getMentor: function(){
			$.get(ajaxServerUrlG("bsnmentor/infoBylogin"), function(r){
				if (r.code == 0) {
					if (r.bsnMentor) {
                		vm.bsnMentor = r.bsnMentor;
					}
				}
            });
		},
		refreshData: function(param) {
			if (param == 'yiyuyue')  {
				vm.getNotFinishedList();
			} else {
				vm.getFinishedList();
			}
		},
        getFinishedList: function () {
        	$('#sct-yiyuyue').hide();
        	$('#sct-yiwancheng').show();
            $.ajax({
                type: "POST",
                url: ajaxServerUrlG("bsngoutongzhidao/listFinished"),
                contentType: "application/json",
                data: JSON.stringify(vm.pageParams),
                success: function (r) {
                    if (r.code === 0) {
                        vm.bsnFinished = r.page.list;
                    } else {
                        alert(r.msg);
                    }
                }
            });
        },
        getNotFinishedList: function () { 
			$('#sct-yiyuyue').show();
        	$('#sct-yiwancheng').hide();
            $.ajax({
                type: "POST",
                url: ajaxServerUrlG("bsngoutongzhidao/list"),
                contentType: "application/json",
                data: JSON.stringify(vm.pageParams),
                success: function (r) {
                    if (r.code === 0) {
                        vm.bsnNotFinished = r.page.list;
                    } else {
                        alert(r.msg);
                    }
                }
            });
        },
        gotoEdit: function(id) {
        	location.href = "mentorZhiDaoEdit.html?id=" + id + "&mentorId=" + vm.bsnMentor.id +
        		"&title=预约指导";
        },
        cancelZhidao: function(id) {
        	var thisUrl = ajaxServerUrlG("bsngoutongzhidao/cancel/"+　id);
			$.get(thisUrl, function(r){
					if(r.code === 0){
                		$('#yiyuyue').click();
					}else{
						alert(r.msg);
					} 
            });
       },
        gotoZhiDaoGoutong: function (id) {
            location.href = "mentorZhiDaoGoutong.html?id=" + id;
        }
    },
    filters: {
        /*过滤并替换头像 */
        imgFilter: function (imgUrl, xingb) {
            // console.log(imgUrl);
            if (StringUtils.isNotEmpty(imgUrl)) {
                return imgUrl;
            }
            if (xingb == "男") {
                return "images/man@2x.png";
            } else {
                return "images/woman@2x.png";
            }
        }
    }
});

